package com.dsh.system.controller;
import com.dsh.model.Result;
import com.dsh.system.entity.Banner;
import com.dsh.system.entity.NoticeVo;
import com.dsh.system.service.BannerService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Banner)表控制层
 *
 * @author makejava
 * @since 2022-05-11 16:51:32
 */
@Api(tags = "轮播图")
@RestController
@RequestMapping("banner")
public class BannerController {
    /**
     * 服务对象
     */
    @Resource
    private BannerService bannerService;

    /**
     * 通过主键查询单条数据
     *
     * @return 单条数据
     */
    @ApiImplicitParam(paramType="query", name = "show", value = "show=1小程序首页，show=2后台广告", required = true, dataType = "int")
    @ApiOperation("查找全部的首页轮播")
    @GetMapping("queryAll")
    public Result queryAll(int show){
        List<Banner> banners = bannerService.queryAll(show);
        return Result.success(banners,"");
    }
    @ApiImplicitParam(paramType="query", name = "id", value = "轮播图id", required = true, dataType = "int")
    @ApiOperation("根据id查询数据")
    @GetMapping("queryById")
    public Result queryById(int id){
        Banner banner = bannerService.queryById(id);
        return Result.success(banner,"");
    }
    @ApiOperation(value = "增加一条轮播数据" ,response = Banner.class)
    @PostMapping("insertOne")
    public Result insertOne(@RequestBody Banner banner){
        int i = bannerService.insertOne(banner);
        return Result.success(i,"");
    }
    @ApiOperation(value = "修改一条轮播数据",response = Banner.class)
    @PostMapping("updateOne")
    public Result updateOne(@RequestBody Banner banner){
        int i = bannerService.updateOne(banner);
        return Result.success(i,"");
    }
    @ApiImplicitParam(paramType="query", name = "id", value = "轮播图id", required = true, dataType = "int")
    @ApiOperation(value = "删除一条轮播数据")
    @PostMapping("deleteOne")
    public Result deleteOne(int id){
        int i = bannerService.deleteOne(id);
        return Result.success(i,"");
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "limit", value = "分页大小", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "page", value = "分页数", required = true, dataType = "int")
    })
    @ApiOperation(value = "查询公告集合")
    @GetMapping("selectAllNotice")
    public Result selectAllNotice(int limit, int page){
        PageInfo<NoticeVo> noticeVoPageInfo = bannerService.selectAllNotice(limit, page);
        return Result.success(noticeVoPageInfo.getList(),"");

    }
    @ApiOperation(value = "修改公告",response = NoticeVo.class)
    @PostMapping("updateNotice")
    public Result updateNotice(@RequestBody NoticeVo noticeVo){
        int i = bannerService.updateNotice(noticeVo);
        return Result.success(i,"");
    }
    @ApiOperation(value = "添加公告",response = NoticeVo.class)
    @PostMapping("insertOneNotice")
    public Result insertOneNotice(@RequestBody NoticeVo noticeVo){
        int i = bannerService.insertOneNotice(noticeVo);
        return Result.success(i,"");
    }
    @ApiImplicitParam(paramType="query", name = "id", value = "公告", required = true, dataType = "int")
    @ApiOperation(value = "删除一条公告数据")
    @PostMapping("deleteOneNotice")
    public Result deleteOneNotice(int id){
        int i = bannerService.deleteOneNotice(id);
        return Result.success(i,"");
    }
    @GetMapping("selectNoticeById")
    public Result selectNoticeById(int id){
        NoticeVo noticeVo = bannerService.selectNoticeById(id);
        return Result.success(noticeVo,"");

    }
}